﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhSystemBLL.produceBLL;
using baseSet.importExport;
using dhDataAcess.dataAcess.produceDataSetTableAdapters ;
using dhDataAcess.dataAcess;
using FastReport;

namespace dhsystem.produceForm.picking
{
    public partial class FrmmachineTable : Form
    {
        public FrmmachineTable()
        {
            InitializeComponent();
        }
        machineTableBLL machine = new machineTableBLL();
        private void FrmmachineTable_Load(object sender, EventArgs e)
        {
            bgSourcemachineTable.DataSource = machine.getmachineTableAll();
            dGridViewmachineTable.DataSource = bgSourcemachineTable;
            DcolumnSet.colSet(moduleInfo.machineTable, dGridViewmachineTable);
            dGridViewmachineTable.EditMode = DataGridViewEditMode.EditOnEnter;

        }

        private void buttonok_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否保存订单表表信息！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    produceDataSet.machineTableDataTable machineTable = (produceDataSet.machineTableDataTable)bgSourcemachineTable.DataSource;
                    machine.machineTableInsert(machineTable);
                    MessageBox.Show("保存成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void dGridViewmachineTable_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void dGridViewmachineTable_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            string field;
            field = "panme";
            if (e.ColumnIndex == dGridViewmachineTable.Columns["panme"].Index)
            {
                Frmprodutselect select = new Frmprodutselect(moduleInfo.productList, field);
                DialogResult result = select.ShowDialog();
                if (result == DialogResult.Yes)
                {
                    dGridViewmachineTable.CurrentCell.Value  = select.pname;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string orderNo = dGridorderproduce.CurrentRow.Cells["orderNo"].Value.ToString();
            //string ptype = dGridorderMaster.CurrentRow.Cells["ptype"].Value.ToString();
            Report r = new Report();
            DataSet ds = new DataSet();
            ds.Tables.Add(machine .getmachineTableAll ());
           // r.Load(@"E:\东华软件项目\报表\machineTable.frx");
            r.Load(@"\\192.168.0.27\东华软件\报表\machineTable.frx");
            //r.Load(@"\\192.168.0.27\东华软件\报表\orderproduce.frx");
            r.RegisterData(ds);
           //r.Design();
           r.Show();
        }

        private void 插入空行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (dGridViewmachineTable.Rows.Count != 1)
                {
                    produceDataSet.machineTableDataTable detailTable = (produceDataSet.machineTableDataTable)bgSourcemachineTable.DataSource;
                    produceDataSet.machineTableRow  insertRow = detailTable.NewmachineTableRow ();
                    detailTable.Rows.InsertAt((DataRow)insertRow, dGridViewmachineTable.CurrentRow.Index + 1);
                    bgSourcemachineTable.MoveNext();
                }
                else
                {
                    MessageBox.Show("不存在需要插入的行");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请选需要插入空行的位置");
            }
        }
    }
}
